<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::TagHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionView::Helpers::TagHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/tag_helper_rb.html">actionpack/lib/action_view/helpers/tag_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Provides methods to generate <a href="../../HTML.html">HTML</a> tags
programmatically when you can’t use a Builder. By default, they output
XHTML compliant tags.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TagHelper.html#method-i-cdata_section">cdata_section</a>,
              </li>
            
              
              <li>
                <a href="TagHelper.html#method-i-content_tag">content_tag</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TagHelper.html#method-i-escape_once">escape_once</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TagHelper.html#method-i-tag">tag</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="CaptureHelper.html">
              ActionView::Helpers::CaptureHelper
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    
      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class="attr-name">BOOLEAN_ATTRIBUTES</td>
            <td>=</td>
            <td class="attr-value">%w(disabled readonly multiple checked autobuffer
autoplay controls loop selected hidden scoped async
defer reversed ismap seemless muted required
autofocus novalidate formnovalidate open pubdate itemscope).to_set</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
          <tr valign='top'>
            <td class="attr-name">PRE_CONTENT_STRINGS</td>
            <td>=</td>
            <td class="attr-value">{
:textarea =&gt; &quot;\n&quot;
}</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
      </table>
    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-cdata_section">
            
              <b>cdata_section</b>(content)
            
            <a href="TagHelper.html#method-i-cdata_section" name="method-i-cdata_section" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a CDATA section with the given <code>content</code>. CDATA sections
are used to escape blocks of text containing characters which would
otherwise be recognized as markup. CDATA sections begin with the string
<code>&lt;![CDATA[</code> and end with (and may not contain) the string
<code>]]&gt;</code>.</p>

<pre class="ruby"><span class="ruby-identifier">cdata_section</span>(<span class="ruby-string">&quot;&lt;hello world&gt;&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;![CDATA[&lt;hello world&gt;]]&gt;</span>

<span class="ruby-identifier">cdata_section</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">&quot;hello_world.txt&quot;</span>))
<span class="ruby-comment"># =&gt; &lt;![CDATA[&lt;hello from a text file]]&gt;</span>

<span class="ruby-identifier">cdata_section</span>(<span class="ruby-string">&quot;hello]]&gt;world&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;![CDATA[hello]]]]&gt;&lt;![CDATA[&gt;world]]&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-cdata_section_source')" id="l_method-i-cdata_section_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/tag_helper.rb#L113" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-cdata_section_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/tag_helper.rb, line 113</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">cdata_section</span>(<span class="ruby-identifier">content</span>)
  <span class="ruby-identifier">splitted</span> = <span class="ruby-identifier">content</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-string">']]&gt;'</span>, <span class="ruby-string">']]]]&gt;&lt;![CDATA[&gt;'</span>)
  <span class="ruby-node">&quot;&lt;![CDATA[#{splitted}]]&gt;&quot;</span>.<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-content_tag">
            
              <b>content_tag</b>(name, content_or_options_with_block = nil, options = nil, escape = true, &amp;block)
            
            <a href="TagHelper.html#method-i-content_tag" name="method-i-content_tag" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an <a href="../../HTML.html">HTML</a> block tag of type
<code>name</code> surrounding the <code>content</code>. Add <a
href="../../HTML.html">HTML</a> attributes by passing an attributes hash to
<code>options</code>. Instead of passing the content as an argument, you
can also use a block in which case, you pass your <code>options</code> as
the second parameter. Set escape to false to disable attribute value
escaping.</p>

<h4 id="method-i-content_tag-label-Options">Options</h4>

<p>The <code>options</code> hash is used with attributes with no value like
(<code>disabled</code> and <code>readonly</code>), which you can give a
value of true in the <code>options</code> hash. You can use symbols or
strings for the attribute names.</p>

<h4 id="method-i-content_tag-label-Examples">Examples</h4>

<pre>content_tag(:p, &quot;Hello world!&quot;)
 # =&gt; &lt;p&gt;Hello world!&lt;/p&gt;
content_tag(:div, content_tag(:p, &quot;Hello world!&quot;), class: &quot;strong&quot;)
 # =&gt; &lt;div class=&quot;strong&quot;&gt;&lt;p&gt;Hello world!&lt;/p&gt;&lt;/div&gt;
content_tag(&quot;select&quot;, options, multiple: true)
 # =&gt; &lt;select multiple=&quot;multiple&quot;&gt;...options...&lt;/select&gt;

&lt;%= content_tag :div, class: &quot;strong&quot; do -%&gt;
  Hello world!
&lt;% end -%&gt;
 # =&gt; &lt;div class=&quot;strong&quot;&gt;Hello world!&lt;/div&gt;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-content_tag_source')" id="l_method-i-content_tag_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/tag_helper.rb#L91" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-content_tag_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/tag_helper.rb, line 91</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">content_tag</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">content_or_options_with_block</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">escape</span> = <span class="ruby-keyword">true</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-identifier">options</span> = <span class="ruby-identifier">content_or_options_with_block</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">content_or_options_with_block</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
    <span class="ruby-identifier">content_tag_string</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">capture</span>(&amp;<span class="ruby-identifier">block</span>), <span class="ruby-identifier">options</span>, <span class="ruby-identifier">escape</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">content_tag_string</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">content_or_options_with_block</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">escape</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-escape_once">
            
              <b>escape_once</b>(html)
            
            <a href="TagHelper.html#method-i-escape_once" name="method-i-escape_once" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an escaped version of <code>html</code> without affecting existing
escaped entities.</p>

<pre class="ruby"><span class="ruby-identifier">escape_once</span>(<span class="ruby-string">&quot;1 &lt; 2 &amp;amp; 3&quot;</span>)
<span class="ruby-comment"># =&gt; &quot;1 &amp;lt; 2 &amp;amp; 3&quot;</span>

<span class="ruby-identifier">escape_once</span>(<span class="ruby-string">&quot;&amp;lt;&amp;lt; Accept &amp; Checkout&quot;</span>)
<span class="ruby-comment"># =&gt; &quot;&amp;lt;&amp;lt; Accept &amp;amp; Checkout&quot;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-escape_once_source')" id="l_method-i-escape_once_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/tag_helper.rb#L125" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-escape_once_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/tag_helper.rb, line 125</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">escape_once</span>(<span class="ruby-identifier">html</span>)
  <span class="ruby-constant">ERB</span><span class="ruby-operator">::</span><span class="ruby-constant">Util</span>.<span class="ruby-identifier">html_escape_once</span>(<span class="ruby-identifier">html</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-tag">
            
              <b>tag</b>(name, options = nil, open = false, escape = true)
            
            <a href="TagHelper.html#method-i-tag" name="method-i-tag" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns an empty <a href="../../HTML.html">HTML</a> tag of type
<code>name</code> which by default is XHTML compliant. Set
<code>open</code> to true to create an open tag compatible with <a
href="../../HTML.html">HTML</a> 4.0 and below. Add <a
href="../../HTML.html">HTML</a> attributes by passing an attributes hash to
<code>options</code>. Set <code>escape</code> to false to disable attribute
value escaping.</p>

<h4 id="method-i-tag-label-Options">Options</h4>

<p>You can use symbols or strings for the attribute names.</p>

<p>Use <code>true</code> with boolean attributes that can render with no
value, like <code>disabled</code> and <code>readonly</code>.</p>

<p>HTML5 <code>data-*</code> attributes can be set with a single
<code>data</code> key pointing to a hash of sub-attributes.</p>

<p>To play nicely with JavaScript conventions sub-attributes are dasherized.
For example, a key <code>user_id</code> would render as
<code>data-user-id</code> and thus accessed as <code>dataset.userId</code>.</p>

<p>Values are encoded to JSON, with the exception of strings and symbols. This
may come in handy when using jQuery’s HTML5-aware <code>.data()</code> from
1.4.3.</p>

<h4 id="method-i-tag-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;br&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;br /&gt;</span>

<span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;br&quot;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;br&gt;</span>

<span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;input&quot;</span>, <span class="ruby-identifier">type</span><span class="ruby-operator">:</span> <span class="ruby-string">'text'</span>, <span class="ruby-identifier">disabled</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;text&quot; disabled=&quot;disabled&quot; /&gt;</span>

<span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;img&quot;</span>, <span class="ruby-identifier">src</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;open &amp; shut.png&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;img src=&quot;open &amp;amp; shut.png&quot; /&gt;</span>

<span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;img&quot;</span>, {<span class="ruby-identifier">src</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;open &amp;amp; shut.png&quot;</span>}, <span class="ruby-keyword">false</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-comment"># =&gt; &lt;img src=&quot;open &amp;amp; shut.png&quot; /&gt;</span>

<span class="ruby-identifier">tag</span>(<span class="ruby-string">&quot;div&quot;</span>, <span class="ruby-identifier">data</span><span class="ruby-operator">:</span> {<span class="ruby-identifier">name</span><span class="ruby-operator">:</span> <span class="ruby-string">'Stephen'</span>, <span class="ruby-identifier">city_state</span><span class="ruby-operator">:</span> <span class="ruby-node">%w(Chicago IL)</span>})
<span class="ruby-comment"># =&gt; &lt;div data-name=&quot;Stephen&quot; data-city-state=&quot;[&amp;quot;Chicago&amp;quot;,&amp;quot;IL&amp;quot;]&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-tag_source')" id="l_method-i-tag_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/be4a4cd38ff2c2db0f6b69bb72fb3557bd5a6e21/actionpack/lib/action_view/helpers/tag_helper.rb#L64" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-tag_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/tag_helper.rb, line 64</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">tag</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">open</span> = <span class="ruby-keyword">false</span>, <span class="ruby-identifier">escape</span> = <span class="ruby-keyword">true</span>)
  <span class="ruby-node">&quot;&lt;#{name}#{tag_options(options, escape) if options}#{open ? &quot;&gt;&quot; : &quot; /&gt;&quot;}&quot;</span>.<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    